<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">敏感词管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>系统管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">敏感词管理</li>
		</ol>
		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">
		<!-- 知识分类s -->
		<div class="panel panel-white">
			<div class="panel-body">
				<div class="demo-btn" id="generalWordList">
					<span class="demo-btn"style="float: left;">
						<p style="float: left;margin-top: 5px;">词名：</p>
						<input id="name" type="text" class="form-control" style="width: 500px;"/>
					</span>
					<span class="demo-btn"style="float: left;margin-left: 15px;margin-top: 2px;">
						<button type="button" class="btn btn-sm btn-info btn-outlined" onclick="querySensitiveWord();">查询</button>
						<button type="button" class="btn btn-sm btn-info btn-outlined" onclick="savefind();">添加</button>
						<button type="button" class="btn btn-sm btn-info btn-outlined" onclick="batchAdd();">批量添加</button>
					</span>
				</div>
			</div>
		</div>
		<!-- 知识分类e -->
		<div class="row">
			<div class="col-lg-12">
				<div class="panel" style="height: auto;overflow: auto;">
					<div class="panel-heading" style="margin-bottom: -10px;">
						敏感词列表 <span class="subtitle">展示敏感词，点击可编辑词表具体条目信息。</span>
						<span class="subtitle" style="float: right;" id="count"> </span>
					</div>
					<div id="wordData" class="panel-body" >
					
					</div>
					<div id="page2" style="text-align: center; margin-top: 10px; margin-bottom: 15px;"></div>
				</div>
			</div>
		</div>
	</div>
	<!--END CONTENT-->
</div>
<?} ?>
<script type="text/javascript">
	function getType() {  
	    return "sensitive";
	} 
	$(function() {
		querySensitiveWord();
	});
	var curr;
	function batchAdd() {
		layer.open({
		    type : 2,
			area : [ '500px', '450px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			title : '批量添加',
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content :["text-field.html",'no'],
			yes: function(index,layer){
				 var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					iframeWin.Page();
	 	    },
			cancel : function(index) {}
		});
	}
	//保存单个
	function savefind(){
		if ($.trim($("#name").val()).length < 1) {
			layer.msg('词名不能为空！');
			return null;
		}
		if ($.trim($("#name").val()).length > 20) {
			layer.msg('词名长度不可超过20个字符！');
			return null;
		}
		if (confirm("是否确认新增敏感词！！")) {
			$.ajax({
				type : "post",
				url : "saveSensitiveWord.do",
				data : {
					"name" : $("#name").val()
				},
				dataType : "json",
				success : function(data) {
					if(data[0].data == 'yes'){
						if(data[0].repetitionWord != null && data[0].repetitionWord != ''){
							alert("发现重复数据："+data[0].repetitionWord);
						}
						layer.msg('添加成功');
						$("#name").val("");
						querySensitiveWord();
					}else{
						layer.msg('添加失败！请检查数据格式...');
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
	//查询
	function querySensitiveWord(){
		$.ajax({
			type : "post",
			url : "querySensitiveWord.do",
			data : {
				"name" : $("#name").val(),
				"page" : curr || 1,
			},
			dataType : "json",
			success : function(data) {
				var src='';
				for ( var i = 0; i < data[0].data.length; i++) {
					src += '<span  class="demo-btn" id="spanShow" >'
						+ '<button name="buValueColor" type="button" class="btn btn-green btn-square" style="margin-top:20px;margin-bottom: -10px; margin-right: 30px;">'
						+ data[0].data[i].wordName
						+ '</button>'
						+ '<a  href="javascript:delgeneralWord('+data[0].data[i].id+');" style="font-size: 18px; margin-right: 5px;"><i style="margin-left: -30px;" class="fa fa-times-circle-o"></i></a></span>';
				}
				if(data[0].count == '0'){
					src ='<span class="subtitle" style="font-size: 15px;">数据为空!</span>';
				}
				$("#wordData").html(src);
				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : data[0].page, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr : curr || 1,
					last: data[0].page,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							curr = obj.curr;
							querySensitiveWord(curr);
						}
					}
				});
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	function delgeneralWord(wordId){
		$.ajax({
			type : "post",
			url : "deleteSensitiveWord.do",
			data : {
				"id" : wordId,
			},
			dataType : "json",
			success : function(data) {
				if(data[0].data == 'yes'){
					layer.msg('删除成功！');
					querySensitiveWord();
				}else{
					layer.msg('删除失败！');
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
</script>
